package com.example.reggie.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.example.reggie.entity.AddressBook;
import com.example.reggie.mapper.AddressBookMapper;
import com.example.reggie.service.AddressBookService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AddressBookServiceImpl extends ServiceImpl<AddressBookMapper, AddressBook> implements AddressBookService {

    /**
     * 保存一个地址
     */
    @Transactional
    @Override
    public boolean updateWithAll(AddressBook addressBook) {
        //获取想删除的地址id
        Long addid = addressBook.getId();
        //删除记录
        this.removeById(addid);
        //增加新纪录
        AddressBook addressBooknew = new AddressBook();
        addressBook.setUpdateTime(null);
        addressBook.setUpdateUser(null);
        BeanUtils.copyProperties(addressBook,addressBooknew,"id");
        boolean save = this.save(addressBooknew);
        if (!save){
            return false;
        }
        return true;
    }

}
